import 'package:flutter/material.dart';

class TextField_Widget extends StatefulWidget {
  const TextField_Widget({Key? key}) : super(key: key);

  @override
  _StartDemoState createState() => _StartDemoState();
}

class _StartDemoState extends State<TextField_Widget> {
  TextEditingController account= TextEditingController();
  TextEditingController password= TextEditingController();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: Text(
            "TextFild练习",
            textDirection: TextDirection.ltr,
          ),
          backgroundColor: Colors.greenAccent,
        ),
        body:  Padding(
          padding: EdgeInsets.all(10),
          child: ListView(
            children: <Widget>[
              AccountWidget(account),
              SizedBox(height: 20),
              PassWordWidget(password),
              SizedBox(height: 20),
              CommitButton(account,password),
            ],
          ),
        ),
      ),
    );
  }
}

class AccountWidget extends StatelessWidget {
  final TextEditingController account;
  const AccountWidget(this.account,{Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return  TextField(
      controller: account,
      decoration: InputDecoration(
        // icon: Icon(Icons.people),//外
          prefixIcon:Icon(Icons.people),
          hintText: "请输入账号",
          border: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(30))
          )
      ),
      keyboardType: TextInputType.text,
    );
  }
}
class PassWordWidget extends StatelessWidget {
  final TextEditingController password;
  const PassWordWidget(this.password,{Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextField(
      obscureText: true,
      controller: password,
      decoration: InputDecoration(
        // icon: Icon(Icons.people),//外
          prefixIcon:Icon(Icons.lock),
          hintText: "请输入密码",
          border: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(30))
          )
      ),
      keyboardType: TextInputType.text,
    );
  }
}

class CommitButton extends StatelessWidget {
  final TextEditingController account,password;
  const CommitButton(this.account,this.password,{Key? key}) : super(key: key);
  void _getData(){
   print(account.text+"===="+password.text);
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      child: RaisedButton(
        onPressed: _getData,
        child: Text("提交数据"),
      ),
    );
  }
}



